package com.affablebeans.model.repository;

import java.sql.SQLException;
import java.util.List;

import javax.sql.DataSource;

import com.affablebeans.model.bll.DefaultTrueValidator;
import com.affablebeans.model.bll.GenericEntityBLL;
import com.affablebeans.model.dal.ProductDAL;
import com.affablebeans.model.entity.Product;

/**
 *  
 * @author Bora SAYINER
 * @since Jan 26, 2015 11:45:55 PM
 * @version 1.0.0
 */
public class Products {

	private final GenericEntityBLL<Product> ProductBLL;
	private final ProductDAL productDAL;

	public Products(DataSource dataSource) {
		productDAL = new ProductDAL(dataSource);
		DefaultTrueValidator<Product> trueValidator = new DefaultTrueValidator<Product>();
		this.ProductBLL = new GenericEntityBLL<Product>(productDAL, trueValidator);
	}

	public boolean insertProduct(Product entity) throws SQLException {
		return ProductBLL.insertEntity(entity);
	}

	public boolean updateProduct(Product entity) throws SQLException {
		return ProductBLL.updateEntity(entity);
	}

	public boolean deleteProduct(Product entity) throws SQLException {
		return ProductBLL.deleteEntity(entity);
	}

	public Product findProductById(int id) throws SQLException {
		return ProductBLL.findEntityById(id);
	}

	public List<Product> getAllProducts() throws SQLException {
		return ProductBLL.getAllEntities();
	}

	public List<Product> findProductByCategory(int id) throws SQLException {
		return productDAL.findByCategory(id);
	}

	public int getCount() throws SQLException {
		return ProductBLL.getEntitiesCount();
	}
}
